package com.bokee.archerwq.lab.wife;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class MarixToRow {
	public static void main(String[] args) throws Exception {
		PrintWriter pw = new PrintWriter(new FileWriter(
				"E:/data/2011-7/2011-nb(7)-rows.txt"));
		int dataLength = 5;

		for (int i = 32; i <= 138; i++) {
			String fileName = "E:/data/2011-7/2011-nb(7)-" + i + ".txt";
			try {
				BufferedReader br = new BufferedReader(new FileReader(fileName));
				pw.print(i + ",");
				String line = null;
				while ((line = br.readLine()) != null && !"".equals(line)) {
					line = new String(line.getBytes("GBK"), "UTF-8");
					System.out.println(">>>" + line);
					String[] items = line.split(",");
					int length = items.length;
					if (length < dataLength) {
						continue;
					}

					List<String> dataList = new ArrayList<String>();
					for (int j = length - 1, k = 0; k < dataLength; j--, k++) {
						dataList.add(items[j]);
					}

					for (int m = dataList.size() - 1; m >= 0; m--) {
						pw.print(dataList.get(m) + ",");
						// if (m == 1) {
						// pw.print(",");
						// }
					}
				}
				br.close();
				pw.println("");
			} catch (FileNotFoundException e) {
				System.out.println("not exist: " + fileName);
				continue;
			}
		}
		pw.flush();
		pw.close();
	}

}
